import {LogLanguage} from "../dist/index.js"

// 测试SQL关键字匹配
const testCases = [
  // 正确的SQL关键字格式（前后有空格）
  "Preparing: SELECT * FROM users",
  "Executing: UPDATE table SET column = value",
  "Query: INSERT INTO logs VALUES (1, 'test')",
  "Statement: DELETE FROM temp_table",
  "Command: CREATE TABLE new_table",
  "Operation: DROP TABLE old_table",
  "Modify: ALTER TABLE users ADD column",
  "Filter: WHERE status = 'active'",
  "Source: FROM customer_table",
  
  // 混合格式
  "2024-01-15 10:30:45 [INFO] Preparing: SELECT * FROM users WHERE status = 'active'",
  
  // 复杂日志行
  "2025-08-06 11:23:02,220 INFO [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] points.PointsProcessor (com.cn.yft.ora.bank.p600030.points.PointsProcessor:64) - Preparing: SELECT * FROM points WHERE user_id = 12345"
]

console.log("=== SQL关键字匹配测试 ===")

testCases.forEach((testCase, index) => {
  console.log(`\n测试 ${index + 1}:`)
  console.log(`输入: ${testCase}`)
  
  // 检查SQL关键字识别
  const sqlRegex = /\s(SELECT|UPDATE|INSERT|DELETE|CREATE|DROP|ALTER|WHERE|FROM)\s/gi
  let match
  let foundKeywords = []
  
  while ((match = sqlRegex.exec(testCase)) !== null) {
    const fullMatch = match[0]  // 完整匹配，包括前后空格
    const keyword = match[1]    // 关键字部分
    const from = match.index + 1  // +1 跳过前面的空格
    const to = from + keyword.length  // 只包含关键字，不包括后面的空格
    
    foundKeywords.push({
      full: fullMatch,
      keyword: keyword,
      from: from,
      to: to,
      highlightedContent: testCase.slice(from, to)
    })
  }
  
  if (foundKeywords.length > 0) {
    console.log("✓ SQL关键字识别成功:")
    foundKeywords.forEach(keyword => {
      console.log(`  - 完整匹配: "${keyword.full}"`)
      console.log(`  - 关键字: "${keyword.keyword}"`)
      console.log(`  - 高亮范围: ${keyword.from}-${keyword.to}`)
      console.log(`  - 高亮内容: "${keyword.highlightedContent}"`)
      console.log(`  - 空格排除: ${keyword.highlightedContent === keyword.keyword ? '✓' : '✗'}`)
      
      // 检查是否包含空格
      const hasLeadingSpace = keyword.highlightedContent.startsWith(' ')
      const hasTrailingSpace = keyword.highlightedContent.endsWith(' ')
      
      if (hasLeadingSpace || hasTrailingSpace) {
        console.log(`  ✗ 错误: 高亮内容包含空格 "${keyword.highlightedContent}"`)
      } else {
        console.log(`  ✓ 正确: 空格已排除 "${keyword.highlightedContent}"`)
      }
    })
  } else {
    console.log("✗ 未找到SQL关键字")
  }
})
